<%--
  Created by IntelliJ IDEA.
  User: hys
  Date: 2020/2/22
  Time: 12:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <title>登录 - 网络笔记</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/common.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/login.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.2.1.js"></script>
    <style type="text/css">
        .linear{
            background-image: linear-gradient(to right, #eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%);
        }
    </style>
</head>
<body class="linear">
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md12 xs-hide"></div>
        <div class="layui-col-md4 layui-col-md-offset4 login-main">
            <div class="main formbox">
                <form method="post" accept-charset="utf-8" class="layui-form" id="loginForm">
                    <div class="inputbox">
                        <input type="text" id="loginname" name="loginname" required  lay-verify="required" placeholder="请输入登录名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="margin20"></div>
                    <div class="inputbox">
                        <input type="password" id="password" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>


                    <div class="inputbox info">

                        <a href="javascript:;"></a><a href="javascript:;"></a>
                    </div>

                </form>
                <div class="layui-row layui-col-space20 bts">
                    <div class="layui-col-md6">
                        <button class="layui-btn" onclick="login()">登录</button>
                    </div>
                    <div class="layui-col-md6">
                        <a href="${pageContext.request.contextPath}/user/toreg" class="layui-btn layui-btn-normal">注册</a>
                    </div>
                    <div class="layui-col-md6">
                        <a class="layui-btn layui-btn-normal" href="${pageContext.request.contextPath}/shareindex" class="layui-btn layui-btn-primary">分享页</a>
                    </div>
                    <div class="layui-col-md6">
                        <a class="layui-btn layui-btn-warm" href="${pageContext.request.contextPath}/forgetpwd" class="layui-btn layui-btn-primary">忘记密码</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script src="${pageContext.request.contextPath}/layui/layui.all.js"></script>
<script>
    function login() {
        //获取表单中的账户和密码
        var loginname = $("#loginname").val();
        var password = $("#password").val();
        //var formData = $("#loginForm").serialize(); //序列化方法，目的：可以获取表单所有输入框的值（键值对方式）
        $.ajax({
            url :  "${pageContext.servletContext.contextPath}/user/login",
            data : {"loginname":loginname,"password":password},
            // data : formData,
            type : "post",
            success : function (msg) {
                // alert(msg);
                console.log(msg);
                if (msg== '101') {
                    //跳转到首页
                    window.location.href = "${pageContext.servletContext.contextPath}/main";
                } else {
                    //提示登录信息出错
                    alert("账户或密码不正确！");
                    return;
                }
            }
        })
    }
</script>
<script type="text/javascript">
    var baseUrl = '${pageContext.request.contextPath}';
</script>
</html>
